package cn.echo42.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * @author DaiZhiZhou
 * @file Spring-Data-JPA
 * @create 2020-07-31 22:48
 */

@Configuration
public class DataSourceConfiguration {

    @Bean("dataSource")
    public DataSource getDataSource(
            @Value("com.mysql.cj.jdbc.Driver") String driverClass,
            @Value("jdbc:mysql:///jpa?serverTimezone=Asia/Shanghai") String url,
            @Value("root") String user,
            @Value("123456") String password) throws PropertyVetoException {
        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        comboPooledDataSource.setDriverClass(driverClass);
        comboPooledDataSource.setJdbcUrl(url);
        comboPooledDataSource.setUser(user);
        comboPooledDataSource.setPassword(password);
        return comboPooledDataSource;
    }
}
